const mongoose = require("mongoose")
const axios = require("axios");
const cheerio = require("cheerio");
const fs = require("fs");
const path = require("path")
const db = require("../model/db")


const ArticleSchema = new mongoose.Schema({
    title: String, //文章标题
    publishDate: Date, //文章发布日期
    content: String, //文章内容
    thumb: String, //缩略图
    description: String //描述
}, {
    versionKey: false,
    timestamps: {
        createdAt: 'createTime',
        updatedAt: 'updateTime'
    } //自动管理修改时间
})
const Article = mongoose.model("Article", ArticleSchema);
async function addArticles(){
    const content = fs.readFileSync(path.join(__dirname, "./data/article.json")).toString();
    const articles = JSON.parse(content)
    articles.forEach(item=>{
        item.publishDate = new Date("2019-"+item.publishDate);
    })
    await Article.create(articles)
}
addArticles();
module.exports = Article;